package com.tx.dao;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.tx.pojo.Employee;

public class Main {
	public static void main(String[] args) throws IOException {

		String resource = "conf.xml";
		InputStream inputStream = Resources.getResourceAsStream(resource);

		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		System.out.println(1);
		SqlSession session = sqlSessionFactory.openSession();

		EmployeeDAO dao = session.getMapper(EmployeeDAO.class);
		/*
		 *  检查selectEmpById整个是否有用  */
//		  Employee emp =dao.selectEmpById(2);
//		 System.out.println(emp);
		

		/* 更新 这是更新，更新对应id的名字*/
//		 Employee emp =new Employee();
//		 emp.setId(6); 
//		 emp.setLast_name("dgxnew66");
//		 
//		 dao.updateEmp(emp); 
//		 session.commit();
//		 session.close();
		
		 

		/*插入 */
//		Employee emp =new Employee(); 
//		emp.setLast_name("ddd233");
//		emp.setGender("nv");
//		 emp.setEmail("dengg@126.com");
//		 emp.setDid(23432); 
//		 dao.insertEmp(emp);
//		 session.commit();
//		 session.close();
		

		/*
		 * 多参数select */
//		 Employee emp =dao.selectEmpByIdAndLastName(3,"ew");
//		 System.out.println(emp);
		


		/*Map对象 */
//		 Map<String,Object> map= new HashMap<String,Object>(); 
//		 map.put("abc", 3);
//		 map.put("bcd","ew"); 
//		 Employee e =dao.selectEmpByIdAndLastName(map);
//		 System.out.println(11);
//		 System.out.println(e);
		
		
		/*List */
//		List<Employee> list =dao.selectAllEmp();
//		System.out.println(list);
		
		/*Map */
//		Map<String,Employee> list =dao.selectAllEmp2();
//		System.out.println(list);
//		
		/* selecttest */
//		Employee emp =dao.selecttest(1, "%dgxnew%66");
//        System.out.println(emp);
		
		/* update set 标签去除后面的, */
//		 Employee emp =new Employee();
//		 emp.setId(6); 
//		 emp.setLastName(null);
//		 emp.setEmail("adddf@126.com");
//		 
//		 dao.updateEmp(emp); 
//		 session.commit();
//		 session.close();
		
		List<Integer> list =new ArrayList<Integer>();
		list.add(1);
		list.add(2);
		list.add(6);
		List<Employee> lists =dao.selectempsById(list);		
		System.out.print(lists);
		
		

	}

}
